package o;

import android.icu.text.AlphabeticIndex;
import android.icu.text.AlphabeticIndex.ImmutableIndex;
import android.os.Build.VERSION;
import android.text.TextUtils;
import java.lang.Character.UnicodeBlock;
import java.util.Collections;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;

public class fpq {
    private static fpq ʻ;
    private static final String ʽ = Locale.JAPANESE.getLanguage();
    public static final Locale ˊ = new Locale("he");
    public static final Locale ˋ = new Locale("th");
    public static final Locale ˎ = new Locale("ar");
    public static final Locale ˏ = new Locale("fa");
    public static final Locale ॱ = new Locale("el");
    public static final Locale ॱॱ = new Locale("uk");
    public static final Locale ᐝ = new Locale("hi");
    private final a ʼ;
    private final Locale ˏॱ;
    private String ͺ;

    static class a {
        private final Locale ˊ;
        protected ImmutableIndex ˋ = null;
        private int ˎ = 0;
        private int ˏ = 0;

        a(Locale locale) {
            this.ˊ = locale;
            Locale locale2 = fpq.ˎ;
            if ("fa".equals(locale.getLanguage())) {
                locale2 = fpq.ˏ;
            }
            if (VERSION.SDK_INT >= 24) {
                this.ˋ = new AlphabeticIndex(locale).setMaxLabelCount(300).addLabels(new Locale[]{Locale.ENGLISH}).addLabels(new Locale[]{Locale.JAPANESE}).addLabels(new Locale[]{Locale.KOREAN}).addLabels(new Locale[]{fpq.ˋ}).addLabels(new Locale[]{locale2}).addLabels(new Locale[]{fpq.ˊ}).addLabels(new Locale[]{fpq.ॱ}).addLabels(new Locale[]{fpq.ॱॱ}).addLabels(new Locale[]{fpq.ᐝ}).buildImmutableIndex();
                this.ˎ = this.ˋ.getBucketCount();
                this.ˏ = this.ˎ - 1;
            }
        }

        private boolean ˎ(int i) {
            int i2;
            int i3 = (Character.isSpaceChar(i) || i == 43) ? 0 : 1;
            if (i != 40) {
                i2 = 1;
            } else {
                i2 = 0;
            }
            int i4 = i3 & i2;
            if (i == 41 || i == 46) {
                i3 = 0;
            } else {
                i3 = 1;
            }
            if (i != 45) {
                i2 = 1;
            } else {
                i2 = 0;
            }
            i3 &= i2;
            if (i != 35) {
                i2 = 1;
            } else {
                i2 = 0;
            }
            i2 &= i3;
            if (i4 == 0 || i2 == 0) {
                return false;
            }
            return true;
        }

        public int ˋ(String str) {
            int i = 0;
            int length = str.length();
            int i2 = 0;
            while (i2 < length) {
                int codePointAt = Character.codePointAt(str, i2);
                if (Character.isDigit(codePointAt) || ˎ(codePointAt)) {
                    break;
                }
                i2 += Character.charCount(codePointAt);
            }
            if (VERSION.SDK_INT >= 24) {
                i = this.ˋ.getBucketIndex(str);
            }
            if (i < 0) {
                return -1;
            }
            if (i >= this.ˏ) {
                return i + 1;
            }
            if (!"TW".equals(this.ˊ.getCountry()) || length <= i2) {
                return i;
            }
            i2 = Character.codePointAt(str, i2);
            if (i2 >= 12549 && i2 <= 12573) {
                return (i2 - 12549) + 1;
            }
            if (i2 < 12573 || i2 > 12585) {
                return i;
            }
            return (i2 - 12550) + 1;
        }

        public int ˊ() {
            return this.ˎ + 1;
        }

        public String ˊ(int i) {
            if (i < 0 || i >= ˊ()) {
                return "";
            }
            if (i == 0) {
                return "#";
            }
            if (i > this.ˏ) {
                i--;
            }
            if (this.ˋ.getBucket(i) == null) {
                return "";
            }
            return this.ˋ.getBucket(i).getLabel();
        }

        public String ॱ(String str) {
            return str;
        }
    }

    static class b extends a {
        b(Locale locale) {
            super(locale);
        }
    }

    static class e extends a {
        private static final Set<UnicodeBlock> ˏ;
        private final int ˎ = super.ˋ("日");

        static {
            Set hashSet = new HashSet();
            hashSet.add(UnicodeBlock.HIRAGANA);
            hashSet.add(UnicodeBlock.KATAKANA);
            hashSet.add(UnicodeBlock.KATAKANA_PHONETIC_EXTENSIONS);
            hashSet.add(UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS);
            hashSet.add(UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS);
            hashSet.add(UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A);
            hashSet.add(UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B);
            hashSet.add(UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION);
            hashSet.add(UnicodeBlock.CJK_RADICALS_SUPPLEMENT);
            hashSet.add(UnicodeBlock.CJK_COMPATIBILITY);
            hashSet.add(UnicodeBlock.CJK_COMPATIBILITY_FORMS);
            hashSet.add(UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS);
            hashSet.add(UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT);
            ˏ = Collections.unmodifiableSet(hashSet);
        }

        e(Locale locale) {
            super(locale);
        }

        private static boolean ˋ(int i) {
            return ˏ.contains(UnicodeBlock.of(i));
        }

        public int ˋ(String str) {
            int i = 0;
            int ˋ = super.ˋ(str);
            if (ˋ == this.ˎ && !ˋ(Character.codePointAt(str, 0))) {
                i = 1;
            }
            if (i != 0 || ˋ > this.ˎ) {
                return ˋ + 1;
            }
            return ˋ;
        }

        public int ˊ() {
            return super.ˊ() + 1;
        }

        public String ˊ(int i) {
            if (i == this.ˎ) {
                return "他";
            }
            if (i > this.ˎ) {
                i--;
            }
            return super.ˊ(i);
        }
    }

    private fpq(Locale locale) {
        if (locale == null) {
            this.ˏॱ = Locale.getDefault();
        } else {
            this.ˏॱ = locale;
        }
        this.ͺ = this.ˏॱ.getLanguage();
        if (this.ͺ.equals(ʽ)) {
            this.ʼ = new e(this.ˏॱ);
        } else if (this.ˏॱ.equals(Locale.CHINA)) {
            this.ʼ = new b(this.ˏॱ);
        } else {
            this.ʼ = new a(this.ˏॱ);
        }
    }

    public static synchronized fpq ˎ() {
        fpq o_fpq;
        synchronized (fpq.class) {
            if (ʻ == null || !ʻ.ˏ(Locale.getDefault())) {
                ʻ = new fpq(null);
            }
            o_fpq = ʻ;
        }
        return o_fpq;
    }

    public boolean ˏ(Locale locale) {
        return this.ˏॱ.equals(locale);
    }

    public String ˋ(String str) {
        if (!TextUtils.isEmpty(str)) {
            char charAt;
            if (this.ˏॱ.getCountry().equals("TW")) {
                charAt = ˏ(str).charAt(0);
                if (charAt >= 'ㄅ' && charAt <= 'ㄩ') {
                    return String.valueOf(charAt);
                }
            }
            if (this.ˏॱ.getLanguage().equals("ar")) {
                charAt = ˏ(str).charAt(0);
                if (charAt < 'ئ' && charAt > 'ء') {
                    return "آ";
                }
            }
        }
        return ˋ(ॱ(ˏ(str)));
    }

    public int ॱ(String str) {
        return this.ʼ.ˋ(str);
    }

    public String ˋ(int i) {
        return this.ʼ.ˊ(i);
    }

    public String ˏ(String str) {
        return this.ʼ.ॱ(str);
    }
}
